#!/bin/bash
echo "📏 mingw64 目录大小和文件数量统计"
echo "=========================================="

PATH1="/c/msys64/mingw64"
PATH2="/d/mingw64"

calculate_size() {
    local path="$1"
    if [ -d "$path" ]; then
        du -sh "$path" 2>/dev/null | awk '{print $1}'
    else
        echo "N/A"
    fi
}

count_files_by_type() {
    local path="$1"
    local dir="$2"
    local full_path="$path/$dir"
    
    if [ ! -d "$full_path" ]; then
        echo "0|0|0|0"
        return
    fi
    
    local headers=$(find "$full_path" -name "*.h" 2>/dev/null | wc -l)
    local libraries=$(find "$full_path" \( -name "*.a" -o -name "*.dll.a" \) 2>/dev/null | wc -l)
    local binaries=$(find "$full_path" \( -name "*.exe" -o -name "*.dll" \) 2>/dev/null | wc -l)
    local total=$(find "$full_path" -type f 2>/dev/null | wc -l)
    
    echo "${headers}|${libraries}|${binaries}|${total}"
}

echo "整体大小对比:"
echo "路径1 ($PATH1): $(calculate_size "$PATH1")"
echo "路径2 ($PATH2): $(calculate_size "$PATH2")"

echo ""
echo "📊 各目录详细对比:"
printf "%-10s | %-15s | %-15s\\n" "目录" "路径1" "路径2"
printf "%-10s-|-%-15s-|-%-15s\\n" "----------" "---------------" "---------------"

for dir in include lib bin; do
    stats1=$(count_files_by_type "$PATH1" "$dir")
    stats2=$(count_files_by_type "$PATH2" "$dir")
    
    IFS='|' read -r h1 l1 b1 t1 <<< "$stats1"
    IFS='|' read -r h2 l2 b2 t2 <<< "$stats2"
    
    printf "%-10s | %-15s | %-15s\\n" "$dir" "总文件: $t1" "总文件: $t2"
    printf "%-10s | %-15s | %-15s\\n" "" "头文件: $h1" "头文件: $h2" 
    printf "%-10s | %-15s | %-15s\\n" "" "库文件: $l1" "库文件: $l2"
    printf "%-10s | %-15s | %-15s\\n" "" "二进制: $b1" "二进制: $b2"
    echo "----------------------------------------------"
done

echo ""
echo "🔍 关键发现:"
echo "- 如果文件数量差异很大，可能是不同版本或不同配置"
echo "- 如果大小差异很大，可能包含不同的调试信息或优化级别"
echo "- 缺失的目录可能表示不完整的安装"
